package com.example.policymode3.factory;

import com.example.policymode3.HolidayDiscount;
import com.example.policymode3.NewerDiscount;
import com.example.policymode3.SecondDiscount;
import com.example.policymode4.AlipayPayment;
import com.example.policymode4.BankCardPayment;
import com.example.policymode4.WxPayment;
import com.example.policymode4.factory.Payment;

import java.util.HashMap;
import java.util.Map;

/**
 * @version 1.0.0
 * @className: DiscountFactory
 * @description:
 * @author: zhangjunfa
 * @date: 2023/1/3 10:42
 */
public class DiscountFactory {
    private static final Map<String, Discount> payStrategies = new HashMap<>();

    static {
        payStrategies.put("假日折扣", new HolidayDiscount());
        payStrategies.put("新用户减免", new NewerDiscount());
        payStrategies.put("第二单8折优惠", new SecondDiscount());
    }

    public static Discount getPayment(String payType) {
        if (payType == null) {
            throw new IllegalArgumentException("pay type is empty.");
        }
        if (!payStrategies.containsKey(payType)) {
            throw new IllegalArgumentException("pay type not supported.");
        }
        return payStrategies.get(payType);
    }
}
